package org.yang.faq.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yang.faq.common.ErrorInfo;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {
    public static final String DEFAULT_ERROR_VIEW="error";

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ErrorInfo<String> jsonErrorHandler(HttpServletRequest request,Exception e){
        ErrorInfo<String> info=new ErrorInfo<String>();
        info.setCode(ErrorInfo.ERROR);
        info.setMessage("出现错误");
        info.setUrl(request.getRequestURL().toString());
        info.setData("出现错误");
        e.printStackTrace();
        return info;
    }

}
